package com.keur.money.ui.user.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.keur.money.R
import com.keur.money.app.MyApp
import com.keur.money.base.adapter.MullaRecyclerViewAdapter
import com.keur.money.base.adapter.MullaViewHolderHelper
import org.json.JSONObject

/**
 * MullaFlow
 * @Author wwdeng
 * @CreateTime: 2024/8/12 17:07
 * @Annotation：用户优惠券列表
 */
class KeurUserCouponAdapter(recyclerView: RecyclerView?) : MullaRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.item_mulla_coupon_user) {

    override fun setItemChildListener(helper: MullaViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.itemLayout) //点击Item
        helper.setItemChildClickListener(R.id.btnUse)
    }

    override fun fillData(helper: MullaViewHolderHelper, position: Int, model: JSONObject) {
        val couponInfo = JSONObject(model.optString("couponInfo"))
        helper.setText(R.id.textAmount,couponInfo.optString("amount"))
        helper.setText(R.id.textUnit,couponInfo.optString("currency"))
        helper.setText(R.id.textFulAmount,String.format(MyApp.app.getString(R.string.coupon_ful_amount),couponInfo.optString("fullAmount")))
        helper.setText(R.id.textExpiresTime,String.format(MyApp.app.getString(R.string.coupon_expires_time),model.optString("expiresTime")))

        val daysLeft = model.optInt("daysLeft")
        helper.setText(R.id.textDaysLeft,"(${String.format(MyApp.app.getString(R.string.home_repayment_days_left),daysLeft.toString())})")
        if (daysLeft <= 7){
            helper.setVisibility(R.id.textDaysLeft, View.VISIBLE)
        } else {
            helper.setVisibility(R.id.textDaysLeft, View.GONE)
        }
    }
}